package day20.zhiyou100;

import java.util.concurrent.*;

// 单例模式
public class Main {
    public static void main(String[] args) throws Exception {
       /* People people = new People();
        People people1 = new People();
        People people2 = new People();
        System.out.println(people);
        System.out.println(people1);
        System.out.println(people2);*/
        /*People people1 = People.getInstance();
        People people2 = People.getInstance();
        People people3 = People.getInstance();
        System.out.println(people1);
        System.out.println(people2);
        System.out.println(people3);*/
        ExecutorService threadPool = Executors.newCachedThreadPool();
        for (int i = 0; i < 7; i++) {
            Future<Student> future = threadPool.submit(new Callable<Student>() {
                @Override
                public Student call() throws Exception {
                    Thread.sleep(1);
                    return Student.getInstance();
                }
            });
            Student student = future.get();
            System.out.println(student);
        }
        Student student = Student.getInstance();
        System.out.println(student);
        threadPool.shutdown();
    }

}

class Student {

    private Student() {
    }

    private final static Student student = new Student();

    public static synchronized Student getInstance() {
        return student;
    }

}

class People {

    private People() {
    }

    private final static People people = new People();

    // 给它提供一个静态方法
    public static synchronized People getInstance() {
        return people;
    }
}
